class Solution {
public:
    int removeDuplicates(int A[], int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
    	if (n <= 1) {
			return n;
		}

		int result = 0;
        int cur = 0;
		for (int i = 0; i < n; ) {
			int j = i;
			while (j < n && A[j] == A[i]) {
				++j;
			}
            A[cur++] = A[i];
			++result;
			i = j;
		}
		return result;

    }
};